12#ifndef AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
13#define AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
17#include "aom_util/aom_pthread.h"
33#define TF_BLOCK_SIZE BLOCK_64X64
36#define TF_WINDOW_LENGTH 5
42static const double SQRT_PI_BY_2 = 1.25331413732;
48#define TF_WEIGHT_SCALE 1000
52#define TF_WINDOW_BLOCK_BALANCE_WEIGHT 5
58#define TF_Q_DECAY_THRESHOLD 20
62#define TF_SEARCH_ERROR_NORM_WEIGHT 20
68#define TF_STRENGTH_THRESHOLD 4
77#define TF_SEARCH_DISTANCE_THRESHOLD 0.1
85#define TF_QINDEX_CUTOFF 128
87#define NOISE_ESTIMATION_EDGE_THRESHOLD 50
105 YV12_BUFFER_CONFIG *
frames[MAX_LAG_BUFFERS];
127 struct scale_factors
sf;
159#define TF_INFO_BUF_COUNT 2
175 YV12_BUFFER_CONFIG
tf_buf[TF_INFO_BUF_COUNT];
244 FRAME_DIFF *frame_diff);
265#if CONFIG_MULTITHREAD
267 pthread_mutex_t *mutex_;
274} AV1TemporalFilterSync;
290void av1_estimate_noise_level(
const YV12_BUFFER_CONFIG *frame,
291 double *noise_level,
int plane_from,
int plane_to,
292 int bit_depth,
int edge_thresh);
334 const int filter_frame_lookahead_idx,
335 int gf_frame_index, FRAME_DIFF *frame_diff,
336 YV12_BUFFER_CONFIG *output_frame);
355 const FRAME_DIFF *frame_diff,
int q_index,
367static inline bool tf_alloc_and_reset_data(TemporalFilterData *tf_data,
368 int num_pels,
int is_high_bitdepth) {
369 tf_data->tmp_mbmi = (
MB_MODE_INFO *)aom_calloc(1,
sizeof(*tf_data->tmp_mbmi));
371 (uint32_t *)aom_memalign(16, num_pels *
sizeof(*tf_data->accum));
373 (uint16_t *)aom_memalign(16, num_pels *
sizeof(*tf_data->count));
374 if (is_high_bitdepth)
375 tf_data->pred = CONVERT_TO_BYTEPTR(
376 aom_memalign(32, num_pels * 2 *
sizeof(*tf_data->pred)));
379 (uint8_t *)aom_memalign(32, num_pels *
sizeof(*tf_data->pred));
382 if (!(tf_data->tmp_mbmi && tf_data->accum && tf_data->count && tf_data->pred))
384 memset(&tf_data->diff, 0,
sizeof(tf_data->diff));
395static inline void tf_setup_macroblockd(MACROBLOCKD *mbd,
396 TemporalFilterData *tf_data,
397 const struct scale_factors *scale) {
400 mbd->
mi = &tf_data->tmp_mbmi;
410static inline void tf_dealloc_data(TemporalFilterData *tf_data,
411 int is_high_bitdepth) {
412 if (is_high_bitdepth)
413 tf_data->pred = (uint8_t *)CONVERT_TO_SHORTPTR(tf_data->pred);
414 aom_free(tf_data->tmp_mbmi);
415 tf_data->tmp_mbmi = NULL;
416 aom_free(tf_data->accum);
417 tf_data->accum = NULL;
418 aom_free(tf_data->count);
419 tf_data->count = NULL;
420 aom_free(tf_data->pred);
421 tf_data->pred = NULL;
433static inline void tf_save_state(MACROBLOCKD *mbd,
MB_MODE_INFO ***input_mbmi,
434 uint8_t **input_buffer,
int num_planes) {
435 for (
int i = 0; i < num_planes; i++) {
436 input_buffer[i] = mbd->
plane[i].pre[0].buf;
438 *input_mbmi = mbd->
mi;
449static inline void tf_restore_state(MACROBLOCKD *mbd,
MB_MODE_INFO **input_mbmi,
450 uint8_t **input_buffer,
int num_planes) {
451 for (
int i = 0; i < num_planes; i++) {
452 mbd->
plane[i].pre[0].buf = input_buffer[i];
454 mbd->
mi = input_mbmi;
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
void av1_temporal_filter(struct AV1_COMP *cpi, const int filter_frame_lookahead_idx, int gf_frame_index, FRAME_DIFF *frame_diff, YV12_BUFFER_CONFIG *output_frame)
Performs temporal filtering if needed on a source frame. For example to create a filtered alternate r...
int av1_check_show_filtered_frame(const YV12_BUFFER_CONFIG *frame, const FRAME_DIFF *frame_diff, int q_index, aom_bit_depth_t bit_depth, int enable_overlay, int is_second_arf)
Check whether a filtered frame can be show directly.
void av1_tf_do_filtering_row(struct AV1_COMP *cpi, struct ThreadData *td, int mb_row)
Does temporal filter for a given macroblock row.
Definition temporal_filter.c:1034
Main encoder configuration data structure.
Definition encoder.h:934
Top level encoder structure.
Definition encoder.h:2897
Data related to the current GF/ARF group and the individual frames within the group.
Definition firstpass.h:343
Stores the prediction/txfm mode of the current coding block.
Definition blockd.h:222
MOTION_MODE motion_mode
The motion mode used by the inter prediction.
Definition blockd.h:250
Temporal filter info for a gop.
Definition temporal_filter.h:164
int tf_buf_display_index_offset[2]
Definition temporal_filter.h:195
YV12_BUFFER_CONFIG tf_buf[2]
Definition temporal_filter.h:175
int tf_buf_gf_index[2]
Definition temporal_filter.h:191
FRAME_DIFF frame_diff[2]
Definition temporal_filter.h:187
int is_temporal_filter_on
Definition temporal_filter.h:170
int tf_buf_valid[2]
Definition temporal_filter.h:199
YV12_BUFFER_CONFIG tf_buf_second_arf
Definition temporal_filter.h:183
Parameters related to temporal filtering.
Definition temporal_filter.h:101
struct scale_factors sf
Definition temporal_filter.h:127
YV12_BUFFER_CONFIG * output_frame
Definition temporal_filter.h:114
int q_factor
Definition temporal_filter.h:151
int num_pels
Definition temporal_filter.h:135
int num_frames
Definition temporal_filter.h:109
int compute_frame_diff
Definition temporal_filter.h:123
int mb_rows
Definition temporal_filter.h:139
int mb_cols
Definition temporal_filter.h:143
double noise_levels[MAX_MB_PLANE]
Definition temporal_filter.h:131
int is_highbitdepth
Definition temporal_filter.h:147
int filter_frame_idx
Definition temporal_filter.h:119
YV12_BUFFER_CONFIG * frames[MAX_LAG_BUFFERS]
Definition temporal_filter.h:105
struct macroblockd_plane plane[3]
Definition blockd.h:606
const struct scale_factors * block_ref_scale_factors[2]
Definition blockd.h:687
MB_MODE_INFO ** mi
Definition blockd.h:617